<?php

class Core_Helper_Website_Helper {

    public function loadModule($name) {
        return App::getModel('website/block')->loadByName($name);
    }

    public function getModules($areaId) {
        return App::getModel('website/collection_block')->joinWebsiteArea()->filterByArea($areaId)->load();
    }

    public function getMenus($areaId) {
        return App::getModel('website/collection_menu')->filterByArea($areaId)->load();
    }

    public function getEnabledBlock($code){
        return App::getModel('website/collection_block')
                ->filterByEnabled(1)
                ->filterByCode($code)
                ->load()
                ->getFirstItem();
    }

    public function getAdPositions() {
        return App::getModel('promotion/collection_ad_position')->load();
    }

    public function getTemplates($areaId = NULL) {
        $result = App::getModel('website/collection_template');
        if (is_null($areaId)) {
            $result->filterByArea($areaId);
        }
        return $result->load();
    }

    public function getModule($templateObject, $position) {
        $result = App::getModel('website/collection_block')
                        ->filterByTemplate($templateObject)
                        ->filterByPosition($position);
        $result->field('b.name','module_name')->asc('sorting')->load();
        return $result;
    }

    public function addSefUrl($type, $sourceId, $sourceUrl, $rewriteUrl, $transaction = NULL) {
        App::getModel('website/sef')
                ->setSourceId($sourceId)
                ->setSourceType($type)
                ->setSourceUrl($sourceUrl)
                ->setRewriteUrl($rewriteUrl)
                ->save($transaction);
    }

    public function deleteSefUrl($type, $sourceId, $transaction = NULL) {
        App::getModel('website/sef')
                ->loadBySourceId($type, $sourceId)
                ->delete($transaction);
        return $this;
    }
    
    public function getSourceUrl($rewriteUrl){
    	
    }
}